import Api from '@/services/api';
import { mapping } from '@/mixin/mixins/mapping';
export default {
  mixins: [mapping],
  data() {
    return {
      title: '',
      info: {}, // 详情数据
      funcInfo: {}, // 功能数据
    }
  },
  computed: {
  },
  onLoad(options) {
    if(options.func){
      this.funcInfo = JSON.parse(options.func);
      uni.setNavigationBarTitle({ title: this.funcInfo.title })
       this.getContent();
    }else{
      this.info = JSON.parse(decodeURIComponent(options.content))
      uni.setNavigationBarTitle({ title: this.info.title })
      this.browseOrLikeNum(this.info.id)
    }

  
  },
  onShow() {
  },
  methods: {
    // 获取内容
    async getContent() {
      const { code, result } = await this.$request({
        url: Api.getContentById,
        data: {
          id: this.idMapping[this.funcInfo.type]
        }
      });
      if (code === 200) {
        this.info = result;
        this.browseOrLikeNum(this.info.id)
      }
    },
    browseOrLikeNum(id){
      this.$request({
        url: Api.addBrowseOrLikeNum,
        data: {
          id: id,
          type:1
        }
      });
    }
  }
}